package Practice2;

import java.io.*;
import java.util.Arrays;

public class IOPractice2 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //第一遍
        //缓冲流复制
        FileInputStream fis1 = new FileInputStream("tu.jpg");
        BufferedInputStream bis1 = new BufferedInputStream(fis1);
        FileOutputStream fos1 = new FileOutputStream("tu1.jpg");
        BufferedOutputStream bos1 = new BufferedOutputStream(fos1);
        int a;
        while((a = bis1.read())!=-1) {
            bos1.write(a);
        }
        System.out.println("复制完毕");
        bis1.close();
        bos1.close();

        //对象流
        FileOutputStream fos2 = new FileOutputStream("Student.obj");
        ObjectOutputStream oos2 = new ObjectOutputStream(fos2);
        Student zs = new Student("张三",18,"男",new String[]{"读书","篮球"});
        oos2.writeObject(zs);
        System.out.println("写入完毕");
        oos2.close();

        FileInputStream fis2 = new FileInputStream("Student.obj");
        ObjectInputStream ois2 = new ObjectInputStream(fis2);
        System.out.println((Student)ois2.readObject());
        System.out.println("读取完毕");
        ois2.close();

        //转换流
        FileOutputStream fos3 = new FileOutputStream("sss.txt");
        OutputStreamWriter osw3 = new OutputStreamWriter(fos3);
        osw3.write("我是一个程序员");
        System.out.println("完毕");
        osw3.close();

        FileInputStream fis3 = new FileInputStream("sss.txt");
        InputStreamReader osr3 = new InputStreamReader(fis3);
        int b;
        while((b = osr3.read())!=-1) {
            System.out.print((char)b);
        }
        System.out.println();
        System.out.println("完毕");
        osr3.close();

        //第二遍
//        //缓冲流
//        FileInputStream fis1 = new FileInputStream("tu.jpg");
//        BufferedInputStream bis1 = new BufferedInputStream(fis1);
//        FileOutputStream fos1 = new FileOutputStream("tu3.jpg");
//        BufferedOutputStream bos1 = new BufferedOutputStream(fos1);
//        int a;
//        while((a = bis1.read())!=-1) {
//            bos1.write(a);
//        }
//        System.out.println("复制完毕");
//        bis1.close();
//        bos1.close();
//
//        //对象流
//        FileOutputStream fos2 = new FileOutputStream("Stu.obj");
//        ObjectOutputStream oos2 = new ObjectOutputStream(fos2);
//        Student ls = new Student("ls",19,"男",new String[]{"游泳","跑步"});
//        oos2.writeObject(ls);
//        System.out.println("完毕");
//        oos2.close();
//
//        FileInputStream fis2 = new FileInputStream("Stu.obj");
//        ObjectInputStream ois2 = new ObjectInputStream(fis2);
//        System.out.println((Student)ois2.readObject());
//        System.out.println("完毕");
//        ois2.close();
//
//        //转换流
//        FileOutputStream fos3 = new FileOutputStream("ccc.txt");
//        OutputStreamWriter osw3 = new OutputStreamWriter(fos3);
//        osw3.write("我一直是一个程序员");
//        System.out.println("完毕");
//        osw3.close();
//
//        FileInputStream fis3 = new FileInputStream("ccc.txt");
//        InputStreamReader isr3 = new InputStreamReader(fis3);
//        int c;
//        while((c = isr3.read())!=-1) {
//            System.out.print((char)c);
//        }
//        System.out.println();
//        System.out.println("完毕");
//        isr3.close();
    }
}

class Student implements Serializable {
    private String name;
    private int age;
    private String gender;
    private transient String[] otherInfo;

    public Student() {
    }

    public Student(String name, int age, String gender, String[] otherInfo) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.otherInfo = otherInfo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String[] getOtherInfo() {
        return otherInfo;
    }

    public void setOtherInfo(String[] otherInfo) {
        this.otherInfo = otherInfo;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                ", otherInfo=" + Arrays.toString(otherInfo) +
                '}';
    }
}
